<template>
  <div>index</div>
  <el-button @click="toPage">跳转</el-button>
  <el-button @click="addCount">++++</el-button>
  {{ userStore.count }}
</template>
<script setup lang="ts">
useHead({
  // title: "index首页",
  meta: [
    {
      name: "description",
      content: "index首页",
    },
  ],
  titleTemplate(title) {
    console.log(title, "title");

    return title + "---index首页";
  },
});
import { onBeforeMount, onMounted, reactive, ref } from "vue";
const emits = defineEmits([]);
const props = defineProps({});
const state = reactive({});
const userStore = useUserStore();
const toPage = async () => {
  console.log(23123);
  await navigateTo({
    path: "/user",
    query: {
      id: 1,
    },
  });
};
//服务端设置的token在客户端获取不到
if (import.meta.server) {
  useUserStore().setToken("3213123");
}
if (import.meta.server) {
  console.log(useUserStore().getToken(), "服务端获取token");
  console.log(useUserStore().count, "服务端获取count");
}
if (import.meta.client) {
  console.log(useUserStore().getToken(), "客户端获取token");
  console.log(useUserStore().count, "客户端获取count");
}

const addCount = () => {
  console.log(userStore.addCount(), "userStoreuserStore");
};
onBeforeMount(() => {});
onMounted(() => {});
defineExpose({ state });
</script>
<style lang="scss" scoped></style>
